<h1>DefineSound</h1>

<p>DefineSound is used to define a sound that will be played when a given event 
occurs.</p>

<table>

<tr>
<th nowrap>Field Name</th>
<th>Type</th>
<th>Size</th>
<th>Description</th>
</tr>

<tr>
<td nowrap valign="top">type</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">10</td>
<td>Identifies the DefineSound instruction when it is encoded. It is encoded 
with the length field as a 16-bit integer (Little-endian byte order).</td>
</tr>

<tr>
<td nowrap valign="top">length</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">6</td>
<td>The length in bytes of the body of the instruction when it is encoded. If the length is greater 
than 62 then this field is set to 0x3F and the length is encoded using the 
extendedLength field. Encoded with the type field as a 16-bit integer.</td>
</tr>

<tr>
<td nowrap valign="top">extendedLength</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">32</td>
<td>Optional. Contains the length in bytes of the encoded instruction if it is
greater than 62 bytes. If the length is 62 bytes or less then this field is 
omitted.</td>
</tr>

<tr>
<td nowrap valign="top">identifier</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>A unique number that identifies the definition within the Flash file.</td>
</tr>

<tr>
<td nowrap valign="top">format</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">4</td>
<td>A code identifying the format of the encoded sound data: 0 = NATIVE_PCM, 
1 = ADPCM, 2 = MP3, 3 = PCM, 6 = NELLYMOSER.</td>
</tr>

<tr>
<td nowrap valign="top">playbackRate</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">2</td>
<td>A code identifying the rate the sound will be played in Hertz: 0 = 5.5KHz, 
1 = 11Khz, 2 = 22KHz or 3 = 44.1KHz.</td>
</tr>

<tr>
<td nowrap valign="top">playbackChannels</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">1</td>
<td>A code identifying the number of channels in the sound: 0 = mono or 1 = stereo.</td>
</tr>

<tr>
<td nowrap valign="top">playbackSampleSize</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">1</td>
<td>A code identifying the number of bits in a sample: 0 = 8-bit, 1 = 16-bit.</td>
</tr>

<tr>
<td nowrap valign="top">sampleCount</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">32</td>
<td>The number of samples in the sound.</td>
</tr>

<tr>
<td nowrap valign="top"><a name="DefineSound_9">sound data</a></td>
<td nowrap valign="top">byte</td>
<td nowrap valign="top" align="right">[n]</td>
<td>The encoded sound data.</td>
</tr>

</table>

<p>Three encoded formats for the sound data are supported:</p>

<div style="padding-left:20px; margin-bottom:10px;">
<ul>
<li>NATIVE_PCM - uncompressed Pulse Code Modulated: samples are either 1 or 2 
bytes. For two-byte samples the byte order is dependent on the platform on which 
the Flash Player is hosted. Sounds created on a platform which supports 
big-endian byte order will not be played correctly when listened to on a platform 
which supports little-endian byte order.</li>

<li>PCM - uncompressed Pulse Code Modulated: samples are either 1 or 2 bytes with 
the latter presented in Little-Endian byte order. This ensures that sounds can be 
played across different platforms.</li>

<li>ADPCM - compressed ADaptive Pulse Code Modulated: samples are encoded and 
compressed by comparing the difference between successive sound sample which 
dramatically reduces the size of the encoded sound when compared to the 
uncompressed PCM formats.</li>

<li>MP3 - compressed MPEG Audio Layer-3.</li>

<li>NELLYMOSER - compressed Nellymoser Asao format supporting low bit-rate sound 
for improving synchronisation between the sound and frame rate of movies.</li>
</ul>
</div>

<p>Two instructions are used to play an event sound:</p>

<div style="padding-left:20px; margin-bottom:10px;">
<ul>
<li>The DefineSound instruction that contains the sampled sound.</li>

<li>A StartSound instruction that signals the Flash Player to begin playing the 
sound and describes how the sound fades in and out, whether it repeats and also
defines an optional envelope for more sophisticated control over how the sound 
is played.</li>
</ul>
</div>

<h2>History</h2>

<p>DefineSound represents the DefineSound structure from the Macromedia 
Flash (SWF) File Format Specification. It was introduced in Flash 1. Flash 3 added 
support for MP3 and the Nellymoser Asao format was added in Flash 6.</p>
